package com.example.demo3.web;

import com.example.demo3.domain.bo.MenuBo;
import com.example.demo3.domain.vo.MenuVo;
import com.example.demo3.service.MenuService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import java.awt.*;
import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("menu")
public class MenuController {


    private final MenuService menuService;


    @GetMapping()
    public PageInfo<MenuVo> list(@RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int pageSize, MenuBo menuBo) {
        PageHelper.startPage(pageNum, pageSize);
        List<MenuVo> menuVoList = menuService.queryMenuList(menuBo);
        return new PageInfo<>(menuVoList);
    }


    @RequiresPermissions("menu:add")
    @PostMapping()
    public String add(@RequestBody Menu menu) {

        return "add success!";
    }


    @RequiresPermissions("menu:edit")
    @PutMapping()
    public String edit() {

        return "admin edit success!";
    }

    @RequiresPermissions("menu:remove")
    @DeleteMapping()
    public String remove() {
        return "delete success!";
    }


}
